#=====================================#
#   用户端
#运行在用户的电脑上
#=====================================#
from WiFi import TX,RX
import socket
import threading
import queue
import cv2 as cv
import numpy
import time

#-----------------------------------------------------#
#   获取本机IP
#-----------------------------------------------------#
'''
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(('8.8.8.8',80))
ip=s.getsockname()[0]
s.close()
'''

ip = input('请输入接收端ip：')
port = input('接收端口：')
#-----------------------------------------------------#
#   创建连接
#-----------------------------------------------------#
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((ip,int(port)))

rx = RX.Recver(sock)

while True:
    img_jpg = rx.msg_buffer[0].get()
    data = numpy.frombuffer(img_jpg,numpy.uint8)
    img = cv.imdecode(data,cv.IMREAD_COLOR)
    cv.imshow('rx',img)
    cv.waitKey(1)
